<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Api站点管理</title>
    <#assign base=request.contextPath  />

    <base id="basePath" href="${base}">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <#--<script type="text/javascript" src="${base}/frame/ztree/jquery-1.4.4.min.js"></script>-->
    <script src="${base}/js/jquery.min.js"></script>

    <#--<script type="text/javascript" src="${base}/city/assets/data.js"></script>-->
    <#--<script type="text/javascript" src="${base}/city/assets/province.js"></script>-->
    <script src="${base}/JQcity/area.js"></script>
    <script src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=ouzH2yPmscyPympLLM1Azii2HLXOyjUy"></script>


    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
            font-family: "微软雅黑", Arial, Helvetica, sans-serif;
        }

        a {
            color: #006600;
            text-decoration: none;
        }

        a:hover {
            color: #990000;
        }

        .top {
            margin: 5px auto;
            color: #990000;
            text-align: center;
        }

        .info select {
            border: 1px #993300 solid;
            background: #FFFFFF;
        }

        /*.info {*/
            /*margin: 5px;*/
            /*text-align: center;*/
        /*}*/

        .info #show {
            color: #3399FF;
        }

        .bottom {
            text-align: right;
            font-size: 12px;
            color: #CCCCCC;
            width: 1000px;
        }
    </style>
    <style type="text/css">
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>
<body>
<br>


<div class="info">
    <div>&nbsp;&nbsp;&nbsp;
        <span style="font-size: 18px;">请选择城市: </span>
        <select id="s_province" name="s_province" style="width: 147px;height: 32px;"></select>  
        <select id="s_city" name="s_city" style="width: 147px;height: 32px;"></select>  
        <select id="s_county" name="s_county" style="width: 147px;height: 32px;" onchange></select>
        <script type="text/javascript">_init_area();</script>
    </div>
    <div id="show"></div>

    <div id="allmap"></div>
    <div id="zuo"></div>

    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">请选择城市: </label>-->
        <#--<div class="layui-input-block">-->
            <#--<select id="s_province" name="s_province" style="width: 147px;height: 32px;"></select>  -->
            <#--<select id="s_city" name="s_city" style="width: 147px;height: 32px;"></select>  -->
            <#--<select id="s_county" name="s_county" style="width: 147px;height: 32px;"></select>-->
        <#--</div>-->
    <#--</div>-->
    <br/>
    <div>
        <button type="button"  class="layui-btn layui-btn-sm layui-btn-normal"
                onclick="zhe()" style="background: #28B779;height: 40px;width: 100px;">添加折扣
        </button>
    </div>


</div>


<table class="layui-hide" id="test"  lay-filter="test"></table>
<#--<script type="text/html" id="barDemo">-->



    <#--&lt;#&ndash;<button type="button" onclick="onDelete('{{d.id}}')" class="layui-btn layui-btn-sm layui-btn-normal"&ndash;&gt;-->
            <#--&lt;#&ndash;lay-event="del" style="background: red;width: 60px;">删除&ndash;&gt;-->
    <#--&lt;#&ndash;</button>&ndash;&gt;-->
<#--</script>-->
<script>


    layui.use(['form', 'layedit', 'laydate', 'layer','table'], function () {

        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;


        var whereData = {}
        whereData.zuo = $("#zuo").val();


        table.render({
            elem: '#test'
            ,url:'${base}/admin/site/selectMyPage'
            ,title: '站点管理'
            ,totalRow: true
            ,toolbar: '#toolbarDemo'//打印
            ,cols:[[
                {type: 'checkbox'}
                ,{field:'id', title: '序号',templet:function(val){
                        return val.LAY_INDEX
                    }, field: true,align:'center'}
                ,{field:'name', title: '名称', align:'center'}
                ,{field:'address', title: '地址', align:'center'}
                ,{field:'discount', title: '优惠信息', align:'center'}
            ]]
            ,id:'testReload'
            ,height:720
            // ,page: {
            //     layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
            //     ,theme: '#0092EF'
            //     ,limit:10
            // }
            ,done: function(res, curr, count){
                this.where={};
            }
        });


        // form.on('select(areaid)', function(data){
        //     console.log(data.elem); //得到select原始DOM对象
        //     console.log(data.value); //得到被选中的值
        //     console.log(data.othis); //得到美化后的DOM对象
        //
        // });





    });


    function zhe() {
        var table = layui.table;
        var checkStatus = table.checkStatus('testReload')
        var data = checkStatus.data;
        console.log(data)
        var ids = []
        var name = []
        var address = []
        for (var i = 0; i < data.length; i++) {
            ids.push(data[i].id+"@"+data[i].name+"@"+data[i].address)

        }
        if (ids.length === 0) {
            layer.msg("请选择数据");
            return;
        }
        layer.open({
            type: 2,
            title: '添加折扣',
            shadeClose: false,
            area: ['400px', '200px'],
            content: '${base}/admin/site/api_discount.html?ids='+ids+"&name="+name+"&address="+address,
            success: function (layero, index) {
                var iframeWin = window[layero.find
                ('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

                //渲染一下form表单
                iframeWin.layui.form.render('select')
            }
        });

        <#--console.log("ids:"+ids)-->
        <#--window.location.href = "${base}/admin/site/api_discount.html?ids="+ids;-->
    }



    //删除
    function onDelete(id){
//提示是否删除这条数据
//data里边的customerId是需要和实体类里边的id是一样的,不然是传不过来参数的
        layer.confirm('真的要删除吗?',function(index){
            var data = {};
            data.id = id;
            $.ajax({
                type:"POST",
                contentType: "application/json;charset=UTF-8",
                url:"${base}/admin/site/deleteByIdSite",
                data:JSON.stringify(data),
                sync:false,
                success:function(data){
                    if(data.code === 200){
                        layer.msg(data.msg)
                        var table = layui.table;
                        //表刷新方法
                        table.reload('testReload', {
                            url:'${base}/admin/site/selectMyPage'
                            ,where: {} //设定异步数据接口的额外参数
                        });
                        //关闭删除是否删除的提示框
                        layer.close(index);
                    }else{
                        layer.msg(data.msg)
                    }

                }
            });
        });
    }

</script>
<script>

    $("#s_county").change(function(){
        var zuobaio = $('#s_city').val();
        console.log("zuobaio:"+zuobaio)
        if(zuobaio!=NaN){
           // 百度地图API功能
           var map = new BMap.Map("allmap");
           var point = new BMap.Point(116.331398,39.897445);
           map.centerAndZoom(point,12);
           // 创建地址解析器实例
           var myGeo = new BMap.Geocoder();
           // 将地址解析结果显示在地图上,并调整地图视野
           myGeo.getPoint(zuobaio, function(point){
               console.log("坐标:"+JSON.stringify(point))
               if (point) {
                   map.centerAndZoom(point, 16);
                   map.addOverlay(new BMap.Marker(point));
                   //$("#zuo").append('<input type="text" value="'+point+'"/>')
                    console.log("lng:"+point.lng)
                    console.log("lat:"+point.lat)

                   var whereData = {}
                   whereData.lng = point.lng;
                   whereData.lat = point.lat;

                   //表刷新方法
                   var table = layui.table;
                   table.reload('testReload', {
                       url: '${base}/admin/site/selectApiMyPage'//数据接口
                       , where: whereData
                   });
               }else{
                   alert("您选择地址没有解析到结果!");
               }
           }, "北京市");
       }

    });
</script>
<script>

</script>
</body>
</html>